package com.dd.machine.main.user.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cn.dd.machine.R;
import com.dd.machine.main.user.model.AppGoodsKind;

import java.util.List;

/**
 * Created by Administrator on 2017/7/7.
 */

public class GoodsKindDetailsAdapter extends BaseAdapter{
    private Context mContext;
    private List<AppGoodsKind> mData;
    private int pos;
    public GoodsKindDetailsAdapter(Context mContext, List<AppGoodsKind> mData) {
        this.mContext = mContext;
        this.mData = mData;
    }
    public void setSelectItemPosition(int position){
        this.pos = position;
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        AppGoodsKind price = mData.get(position);
        if (convertView==null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_kinddetatils,null);
            viewHolder.kid_kind_rel = (RelativeLayout) convertView.findViewById(R.id.kid_kind_rel);
            viewHolder.kid_kind_tv = (TextView) convertView.findViewById(R.id.kid_kind_tv);

            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.kid_kind_tv.setText(price.getTypeName().split(",")[0]);
        if (position == pos) {
            viewHolder.kid_kind_rel.setBackgroundResource(R.drawable.shape_selected_background);
            viewHolder.kid_kind_tv.setTextColor(Color.parseColor("#ffffff"));
        }else {
            viewHolder.kid_kind_rel.setBackgroundResource(R.drawable.shape_noselected_background);
            viewHolder.kid_kind_tv.setTextColor(Color.parseColor("#999999"));
        }

        return convertView;
    }

    class ViewHolder{
        RelativeLayout kid_kind_rel;
        TextView kid_kind_tv;
    }
}
